package com.atguigu.gulimall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 订单确认页Vo
 */
@ToString
public class OrderConfirmVo {

    //防止令牌，防止重复提交的Token
    @Getter
    @Setter
    String orderToken;


    //收货地址
    @Getter
    @Setter
    private List<MemberAddressVo> address;

    //所有选中的购物项
    @Getter
    @Setter
    private List<OrderItemVo> items;

    //会员积分信息
    @Getter
    @Setter
    private Integer integration;

    //库存信息
    @Getter
    @Setter
    Map<Long,Boolean> stocks;

    //订单总额
    private BigDecimal total;

    //计算订单中商品总数
    public Integer getCount(){
        Integer i = 0;
        if (items!=null){
            for (OrderItemVo item : items) {
                i+=item.getCount();
            }
        }
        return i;
    }

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if (items != null) {
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                sum = sum.add(multiply);
            }
        }
        this.total = sum;
        return sum;
    }

    //应付价格
    private BigDecimal payPrice;

    public BigDecimal getPayPrice() {
        this.payPrice = getTotal();
        return payPrice;
    }

    //发票...优惠劵...

}
